package com.core.service.impl;

import java.util.List;

import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.core.dao.UserDAO;
import com.core.model.User;
import com.core.service.UserService;
 
 
 
@Service
public class UserServiceImpl extends ServiceImpl<BaseMapper<User>, User> implements UserService{
 
    @Autowired
    @Qualifier("userDAO")
    private UserDAO userDAO;
     
    public long insertUser(User user) {
        return userDAO.insert(user);
    }

	@Override
	public boolean test() {
		List<User> u = userDAO.selectList(null);
		int i = 0;
		for(User user : u){
			System.out.println(u.get(i).getName());
			i++;
		}
		return false;
	}
	
    public Page<User> selectPage(Page<User> page, EntityWrapper<User> entityWrapper) {
    	if (null != entityWrapper) {
    		entityWrapper.orderBy(page.getOrderByField(), page.isAsc());
    	 }
    	 page.setRecords(userDAO.selectPage(page, entityWrapper));
    	 return page;
    }

	@Override
	public User loginTest(User user, Page<User> page, EntityWrapper<User> entityWrapper) {
	    /*
	     * 实体带查询使用方法  输出看结果
	     */
		entityWrapper.setEntity(new User());
		entityWrapper.where("name={0} AND password={1}", user.getName(), user.getPassword());
		System.out.println(entityWrapper.getSqlSegment());
		return userDAO.loginTest(entityWrapper);
	}
 
}